home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Fireworks 3 / Settings / Commands / Web / Create Shared Palette.jsf next >
Encoding:
Text File  |  1999-11-19  |  1.8 KB  |  60 lines

  1.  
  2. // Copyright (c) 1999 Macromedia. All rights reserved.
  3.  
  4. var message = confirm("This command creates a shared palette from multiple files. Select OK and choose a folder of images.");
  5.  
  6. if (message == true)
  7. {
  8.     var path = fw.browseForFolderURL("Select Folder");
  9.     var numberOfColors = prompt("Enter the maximum number of colors for the shared palette:","128");
  10.     if (numberOfColors !=null && numberOfColors != 0){
  11.     var listOfFiles = Files.enumFiles(path);
  12.     for (var i in listOfFiles) {
  13.         if (!IsOpenableFile(listOfFiles[i])) {
  14.             listOfFiles[i] = null;
  15.         }
  16.     }
  17.  
  18.     // passing an array of URLs is equivalent to "Open Multiple As Animation"
  19.     var newDoc = fw.openDocument(listOfFiles);
  20.  
  21.     // make sure it's Animated GIF with the right number of colors.
  22.     newDoc.setExportOptions({ exportFormat:"GIF animation", numEntriesRequested:numberOfColors });
  23.     newDoc.rebuildColorTable();
  24.  
  25.     var newPalettePath = fw.browseForFileURL("save", "Save Palette", true);
  26.     if (newPalettePath != null) {
  27.         // saveColorPalette() does not force the correct file extension, so let's do it here.
  28.         newPalettePath = SetExtension(newPalettePath, ".act");
  29.         newDoc.exportOptions.saveColorPalette(newPalettePath);
  30.         newDoc.exportOptions.loadColorPalette(newPalettePath);
  31.     }
  32.  
  33. }
  34.  
  35. // -----------------------------------------------------------
  36.  
  37. function IsOpenableFile(path)
  38. {
  39.     var gOpenableExtensions = [ ".gif", ".jpg", ".jpeg", ".png", ".psd" ];
  40.     var ext = Files.getExtension(path).toLowerCase();
  41.     for (var i in gOpenableExtensions) {
  42.         if (ext == gOpenableExtensions[i])
  43.             return true;
  44.     }
  45.     return false;
  46. }
  47.  
  48. // -----------------------------------------------------------
  49.  
  50. function SetExtension(pathname, ext)
  51. {
  52.     var filename = Files.getFilename(pathname, true);    // strip extension
  53.     return Files.setFilename(pathname, filename + ext);
  54. }
  55.  
  56. }
  57.  
  58. var result = true;
  59. result;
  60.